<template>
    <div class="history">
        <el-radio-group v-model="time" size="small">
            <el-radio-button label="1">前天</el-radio-button>
            <el-radio-button label="2">昨天</el-radio-button>
            <el-radio-button label="3">今天</el-radio-button>
        </el-radio-group>
        <el-table
            class="tables"
            border
            size="mini"
            :header-cell-style="{background:'#ccc'}"
            :data="historyList"
            stripe
            style="width: 100%"
            @row-click="toDetail"
            show-summary
        >
            <el-table-column prop="issue" label="期数" min-width="90">
                <template slot-scope="scope">
                    <span style="color:#ef4f4f">{{scope.row.issue}}</span>
                </template>
            </el-table-column>
            <el-table-column prop="quantity" label="笔数" min-width="30"></el-table-column>
            <el-table-column prop="itemAmount" label="金额" min-width="30"></el-table-column>
            <el-table-column prop="isWinName" label="中奖" min-width="50"></el-table-column>
            <el-table-column prop="backAmount" label="回水" min-width="30"></el-table-column>
            <el-table-column prop="profit" label="盈亏" min-width="30"></el-table-column>
        </el-table>
        <el-pagination
            :pager-count="5"
            @current-change="fy"
            :current-page.sync="curpages"
            size="mini"
            :page-size="20"
            background
            layout="prev, pager, next"
            :total="total"
        ></el-pagination>
    </div>
</template>
 
<script>
import { mapState } from "Vuex";
export default {
    name: "history",
    data() {
        return {
            time: "3",
            historyList: [],
            pages: 1,
            curpages: 1,
            total: 100
        };
    },
    computed: {
        ...mapState(["saveType"])
    },
    watch: {
        saveType() {
            if (this.saveType == undefined) {
                this.saveType = 1;
            }
            this.getBill();
        },
        time() {
            this.curpages = 1;
            this.getBill();
        }
    },
    created() {
        if (this.saveType == undefined) {
            this.saveType = 1;
        }
        this.getBill();
    },
    methods: {
        toDetail(val){
            console.log(val)
            this.$router.push({path:'/detail',query:{id:val.issue}})
        },
        getBill() {
            console.log(this.time);
            var params = {
                pageNum: this.pages,
                pageSize: 20,
                startDay: "",
                endDay: "",
                module: this.saveType
            };
            var day = new Date();
            if (this.time == 3) {
                params.endDay = this.timeToDate(day.getTime() / 1000);
                params.startDay = this.timeToDate(
                    (day.getTime() - 24 * 60 * 60 * 1000) / 1000
                );
            } else if (this.time == 2) {
                params.endDay = this.timeToDate(
                    (day.getTime() - 24 * 60 * 60 * 1000) / 1000
                );
                params.startDay = this.timeToDate(
                    (day.getTime() - 24 * 60 * 60 * 1000 * 2) / 1000
                );
            } else if (this.time == 1) {
                params.endDay = this.timeToDate(
                    (day.getTime() - 24 * 60 * 60 * 1000 * 2) / 1000
                );
                params.startDay = this.timeToDate(
                    (day.getTime() - 24 * 60 * 60 * 1000 * 3) / 1000
                );
            }
            this.$api.post(this.$url.bill, params, res => {
                console.log(res.data);
                if (res.data.code == 200) {
                    this.total = res.data.count;
                    this.historyList = res.data.data;
                }
            });
        },
        fy(val) {
            console.log(val);
            this.pages = val;
            this.getBill();
        },
        timeToDate(data) {
            var d = new Date(data * 1000); //时间戳记得乘以1000再进行处理
            var year = d.getFullYear();
            if (d.getMonth().toString().length == 1) {
                var month = "0" + (d.getMonth() + 1);
            } else {
                var month = d.getMonth() + 1;
            }

            if (d.getDate().toString().length == 1) {
                var date = "0" + d.getDate();
            } else {
                var date = d.getDate();
            }

            var hour = d.getHours();
            var minute = d.getMinutes();
            var second = d.getSeconds();
            return year + "-" + month + "-" + date;
        }
    }
};
</script>
 
<style scoped lang="less">
.history {
    padding: 0 5px 5px;
    box-sizing: border-box;
    .tables {
        margin: 10px 0;
    }
}
</style>
